import 'package:encrypt_and_decrypt_files/widget/extension.dart';
import 'package:encrypt_and_decrypt_files/widget/local_language_provider.dart';
import 'package:encrypt_and_decrypt_files/widget/theme_provider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class SelectLanguagePage extends StatefulWidget {
  const SelectLanguagePage({super.key});

  @override
  State<SelectLanguagePage> createState() => _SelectLanguagePageState();
}

class _SelectLanguagePageState extends State<SelectLanguagePage> {
  @override
  Widget build(BuildContext context) {
    final themeProvider = Provider.of<ThemeProvider>(context);
    final languageProvider = Provider.of<LanguageProvider>(context);

    return Scaffold(
      appBar: AppBar(
        title: Text('Select Language'.t(context)),
        backgroundColor: themeProvider.mainColor,
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Row(
              children: [
                Checkbox(
                    value: languageProvider.locale == 'en',
                    onChanged: (value) {
                      languageProvider.setLocale('en');
                    }),
                Expanded(
                  child: ListTile(
                    leading: const Icon(Icons.language),
                    title: Text('English'.t(context)),
                    onTap: () {
                      languageProvider.setLocale('en');
                    },
                  ),
                ),
              ],
            ),
            Row(
              children: [
                Checkbox(
                    value: languageProvider.locale == 'zh',
                    onChanged: (value) {
                      languageProvider.setLocale('zh');
                    }),
                Expanded(
                  child: ListTile(
                    leading: const Icon(Icons.language),
                    title: Text('Chinese'.t(context)),
                    onTap: () {
                      languageProvider.setLocale('zh');
                      Navigator.pop(context);
                    },
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
